package com.example.myapp;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import java.util.ArrayList;
import java.util.List;

public class HomeFragment extends Fragment {

    @Nullable
    @Override
    public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container,
                             @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_home, container, false);

        RecyclerView recyclerView = view.findViewById(R.id.recyclerView);
        recyclerView.setLayoutManager(new GridLayoutManager(getContext(), 2));

        // 初始化模块数据
        List<Feature> featureList = new ArrayList<>();
        featureList.add(new Feature(R.drawable.voice_call, "语音通话"));
        featureList.add(new Feature(R.drawable.environment_recognition, "环境识别"));
        featureList.add(new Feature(R.drawable.location_navigation, "定位导航"));
        featureList.add(new Feature(R.drawable.health_monitoring, "健康检测"));
        featureList.add(new Feature(R.drawable.log_recording, "日志记录"));
        featureList.add(new Feature(R.drawable.emergency_help, "紧急求助"));
        featureList.add(new Feature(R.drawable.risk_detection, "风险检测"));
        featureList.add(new Feature(R.drawable.device_detection, "设备检测"));

        FeatureAdapter adapter = new FeatureAdapter(featureList);
        recyclerView.setAdapter(adapter);

        return view;
    }
}
